﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestUpMVC.Test.TestClasses;

namespace RestUpMVC.Test
{
    [TestClass]
    public class RestUpMvcConfigurationTest
    {
        [TestMethod]
        public void SetBaseUri_ShouldRemoveLeadingForwardSlashCharsFromUri()
        {
            RestUpMvcConfiguration.Instance.SetBaseUri("/uri");
            Assert.AreEqual("uri", RestUpMvcConfiguration.Instance.BaseUri);
        }

        [TestMethod]
        public void SetBaseUri_ShouldRemoveTrailingForwardSlashCharsFromUri()
        {
            RestUpMvcConfiguration.Instance.SetBaseUri("uri/");
            Assert.AreEqual("uri", RestUpMvcConfiguration.Instance.BaseUri);
        }

        [TestMethod]
        public void RegisterRepresentation_ShoulAddTheRepresentationToTheRepresentationFactory()
        {
            var testRepresentation = new TestRepresentation();
            RestUpMvcConfiguration.Instance.RegisterRepresentation(testRepresentation);
            var factory = RestUpMvcConfiguration.Instance.RepresentationFactory;
            var representation = factory.GetRepresentationForContentType(testRepresentation.ContentType, null);
            Assert.IsNotNull(representation);
        }

        [TestMethod]
        public void RepresentationFactory_ShouldAlwaysReturnTheSameInstance()
        {
            Assert.AreSame(RestUpMvcConfiguration.Instance.RepresentationFactory, RestUpMvcConfiguration.Instance.RepresentationFactory);
        }
    }
}
